
/*
 *
 * Copyright (C) 2008 Mattias Blomqvist, patr-blo at dsv dot su dot se
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using ClientExample.Containers;
using ClientExample.Comparers;
using FlowLib.Containers;

namespace ClientExample.Controls
{
    public partial class SearchResultPanel : UserControl
    {
        protected PropertyContainer<string, List<SearchResultInfo>> results = new PropertyContainer<string, List<SearchResultInfo>>();
        Timer updateTimer = new Timer();
        protected bool isUpdating = false;
        protected bool isDirty = false;
        protected int sortColumnIndex = 0;

        public SearchResultPanel()
        {
			IntPtr h = Handle;  // This is for stupid mono stuff. Some how handle isnt created correctly if we dont do this :(
            InitializeComponent();
        }

        public void AddResult(SearchResultInfo sr)
        {
            string key = string.Empty;
            if (sr.Info.ContainsKey(ContentInfo.TTH))
                key = sr.Info.Get(ContentInfo.TTH);
            else
                key = DateTime.Now.Ticks.ToString();    // We dont have any unique value so we will take current time as a temporary value.

            SearchResultGroup group = new SearchResultGroup(key);
            int pos = 0;
            if ((pos = listViewSearchResult1.AllItems.BinarySearch(group)) >= 0)
            {
                group = listViewSearchResult1.AllItems[pos];
                group.Add(sr);
            }
            else
            {
                group.Add(sr);
                listViewSearchResult1.AllItems.Add(group);
            }
            isDirty = true;
        }
    }
}
